/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.auction.service.impl;

import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.modules.auction.domain.YxTerracePayInfo;
import co.yixiang.modules.auction.service.YxTerracePayInfoService;
import co.yixiang.modules.auction.service.dto.YxTerracePayInfoDto;
import co.yixiang.modules.auction.service.dto.YxTerracePayInfoQueryCriteria;
import co.yixiang.modules.auction.service.mapper.YxTerracePayInfoMapper;
import co.yixiang.utils.FileUtil;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;

/**
* @author hupeng
* @date 2021-06-03
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "yxTerracePayInfo")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxTerracePayInfoServiceImpl extends BaseServiceImpl<YxTerracePayInfoMapper, YxTerracePayInfo> implements YxTerracePayInfoService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public Map<String, Object> queryAll(YxTerracePayInfoQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<YxTerracePayInfo> page = new PageInfo<>(queryAll(criteria));
        Map<String, Object> map = new LinkedHashMap<>(2);
        map.put("content", generator.convert(page.getList(), YxTerracePayInfoDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }


    @Override
    //@Cacheable
    public List<YxTerracePayInfo> queryAll(YxTerracePayInfoQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(YxTerracePayInfo.class, criteria));
    }


    @Override
    public void download(List<YxTerracePayInfoDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (YxTerracePayInfoDto yxTerracePayInfo : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("标题", yxTerracePayInfo.getTitle());
            map.put("支付宝名", yxTerracePayInfo.getZfbName());
            map.put("支付宝图片", yxTerracePayInfo.getZfbCode());
            map.put("支付宝号", yxTerracePayInfo.getZfbNum());
            map.put("微信名", yxTerracePayInfo.getWxName());
            map.put("微信图片", yxTerracePayInfo.getWxCode());
            map.put("微信账户", yxTerracePayInfo.getWxNum());
            map.put("银行开户行", yxTerracePayInfo.getYhkhh());
            map.put("银行卡真实姓名", yxTerracePayInfo.getYhzsxm());
            map.put("银行卡卡号", yxTerracePayInfo.getYhkh());
            map.put("银行卡图片", yxTerracePayInfo.getYhtp());
            map.put("创建时间", yxTerracePayInfo.getCreateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
